package com.fhz.loginmvvm

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import com.fhz.loginmvvm.callback.ApiSuccessResponse
import com.fhz.loginmvvm.databinding.ActivityMainBinding
import com.fhz.loginmvvm.viewmodel.MainViewModel
import com.fhz.loginmvvm.viewmodel.MainViewModelFactory

/**
 * mvvm架构图
 * 1,databinding
 * 2,viewmodel
 * 3,livedata
 * 4,room
 * 5,hilt
 *
 */
class MainActivity : AppCompatActivity() {
    private lateinit var binding : ActivityMainBinding

    private lateinit var viewModel: MainViewModel

    private  val TAG = "MainActivity"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
//        val contentView =
//            DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)
        setContentView(binding.root)

        viewModel = ViewModelProvider(this,MainViewModelFactory()).get(MainViewModel::class.java)

        viewModel.login("q1","1").observe(this){
//            val apiSuccessResponse = it as ApiSuccessResponse
//            binding.user = apiSuccessResponse.body.data
//            Log.i(TAG, "onCreate: $apiSuccessResponse")
        }
//        viewModel.user.observe(this){
//            Log.i(TAG, "onCreate: $it")
//        }

        viewModel.login4Local(0).observe(this){
            println(it)
        }

    }
}